<template>
  <view class="success-page">
    <!-- 顶部背景 -->
    <view class="success-header">
      <view class="header-content">
        <view class="back-btn" @click="navigateBack">
          <image class="back-icon" :src="headerConfig.backIcon" mode="aspectFit"></image>
        </view>
        <view class="title" :style="{color: headerConfig.titleColor}">{{ headerConfig.title }}</view>
      </view>
    </view>
    
    <!-- 成功内容 -->
    <view class="success-content">
      <!-- 成功图标 -->
      <view class="success-icon-container" :style="{backgroundColor: successConfig.iconBgColor}">
        <image class="success-icon" src="/static/Images/common/Chenggong.png" mode="aspectFit"></image>
      </view>
      
      <!-- 成功信息 -->
      <view class="success-info">
        <view class="success-title">{{ successConfig.title }}</view>
        <view class="success-desc" v-for="(desc, index) in successConfig.descriptions" :key="index">{{ desc }}</view>
      </view>
      
      <!-- 返回按钮 -->
      <button class="return-btn" :style="{backgroundColor: successConfig.btnColor}" @click="handleButtonClick">{{ successConfig.btnText }}</button>
    </view>
    
    <!-- 底部指示器 -->
    <view class="bottom-indicator"></view>
  </view>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';

// 成功类型配置
const successTypes = {
  payment: {
    headerConfig: {
      title: '支付成功',
      backIcon: '/static/Images/pay/Fanhui.png',
      titleColor: '#333333'
    },
    successConfig: {
      title: '支付成功！',
      descriptions: ['您已完成支付', '感谢您对平台的支持'],
      iconBgColor: '#ff4d4f',
      btnText: '返回首页',
      btnColor: '#FF3037',
      returnPath: '/pages/index',
      returnType: 'switchTab'
    }
  },
  withdraw: {
    headerConfig: {
      title: '提现成功',
      backIcon: '/static/Images/wallet/Fanhuibai.png',
      titleColor: '#111111'
    },
    successConfig: {
      title: '提现提交成功！',
      descriptions: ['提现已申请成功', '请留意平台审核状态！'],
      iconBgColor: '#00c853',
      btnText: '返回钱包',
      btnColor: '#FF3037',
      returnPath: '/pages/wallet/index',
      returnType: 'navigateBack',
      delta: 2
    }
  },
  recharge: {
    headerConfig: {
      title: '充值成功',
      backIcon: '/static/Images/wallet/Fanhui.png',
      titleColor: '#fff'
    },
    successConfig: {
      title: '充值成功！',
      descriptions: ['已成功充值至您的账户'],
      iconBgColor: '#ff4d4f',
      btnText: '返回钱包',
      btnColor: '#FF3037',
      returnPath: '/pages/wallet/index',
      returnType: 'navigateBack',
      delta: 2
    }
  },
  verification: {
    headerConfig: {
      title: '认证成功',
      backIcon: '/static/Images/wallet/Fanhui.png',
      titleColor: '#333333'
    },
    successConfig: {
      title: '认证成功！',
      descriptions: ['您的身份已成功认证', '现在可以使用更多功能了'],
      iconBgColor: '#1890ff',
      btnText: '返回个人中心',
      btnColor: '#FF3037',
      returnPath: '/pages/user/index',
      returnType: 'switchTab'
    }
  },
  logout: {
    headerConfig: {
      title: '注销成功',
      backIcon: '/static/Images/wallet/Fanhui.png',
      titleColor: '#333333'
    },
    successConfig: {
      title: '注销成功！',
      descriptions: ['您的账号已成功注销', '感谢您的使用'],
      iconBgColor: '#52c41a',
      btnText: '返回登录页',
      btnColor: '#FF3037',
      returnPath: '/pages/login/index',
      returnType: 'reLaunch'
    }
  }
};

// 默认使用支付成功配置
const headerConfig = ref(successTypes.payment.headerConfig);
const successConfig = ref(successTypes.payment.successConfig);

// 获取URL参数
onMounted(() => {
  const pages = getCurrentPages();
  const currentPage = pages[pages.length - 1];
  const type = currentPage.options.type || 'payment';
  const amount = currentPage.options.amount;
  
  // 根据类型设置配置
  if (successTypes[type]) {
    headerConfig.value = successTypes[type].headerConfig;
    successConfig.value = {...successTypes[type].successConfig};
    
    // 如果有金额参数，添加到描述中
    if (amount && (type === 'payment' || type === 'recharge' || type === 'withdraw')) {
      const amountDesc = `金额：¥${amount}`;
      successConfig.value.descriptions.push(amountDesc);
    }
  }
});

// 返回上一页
const navigateBack = () => {
  uni.navigateBack();
};

// 处理按钮点击
const handleButtonClick = () => {
  const config = successConfig.value;
  
  switch (config.returnType) {
    case 'navigateBack':
      uni.navigateBack({
        delta: config.delta || 1
      });
      break;
    case 'switchTab':
      uni.switchTab({
        url: config.returnPath
      });
      break;
    case 'reLaunch':
      uni.reLaunch({
        url: config.returnPath
      });
      break;
    default:
      uni.navigateTo({
        url: config.returnPath
      });
  }
};
</script>

<style lang="scss">
.success-page {
  min-height: 100vh;
  background-color: #f5f5f5;
  position: relative;
}

/* 顶部背景 */
.success-header {
  position: relative;
  width: 100%;
  height: 200rpx;
  background-color: #fff;
}

.header-content {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 80rpx;
  position: relative;
}

.back-btn {
  position: absolute;
  left: 30rpx;
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-icon {
  width: 40rpx;
  height: 40rpx;
}

.title {
  font-size: 36rpx;
  font-weight: 500;
  text-align: center;
}

/* 成功内容 */
.success-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 120rpx 30rpx 60rpx;
}

.success-icon-container {
  width: 160rpx;
  height: 160rpx;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 40rpx;
}

.success-icon {
  width: 100%;
  height: 100%;
}

.success-info {
  text-align: center;
  margin-bottom: 60rpx;
}

.success-title {
  font-size: 36rpx;
  font-weight: 500;
  color: #333;
  margin-bottom: 20rpx;
}

.success-desc {
  font-size: 28rpx;
  color: #999;
  line-height: 1.6;
  margin-bottom: 8rpx;
}

/* 返回按钮 */
.return-btn {
  width: calc(100% - 60rpx);
  height: 90rpx;
  line-height: 90rpx;
  color: #fff;
  font-size: 32rpx;
  font-weight: 500;
  border-radius: 45rpx;
  margin: 80rpx auto 40rpx;
  border: none;
  box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.2);
}

/* 底部指示器 */
.bottom-indicator {
  width: 120rpx;
  height: 8rpx;
  background-color: #ddd;
  border-radius: 4rpx;
  margin: 30rpx auto;
  position: absolute;
  bottom: 30rpx;
  left: 50%;
  transform: translateX(-50%);
}
</style>